<?php

namespace app\company\controller;

use app\admin\model\department\Lists;
use app\admin\model\Dynamic;
use app\admin\model\Slide;
use app\admin\model\user\Sign;
use app\common\controller\Api;
use app\common\controller\CompanyApi;
use app\common\model\Category;
use app\common\model\Config;
use think\Db;

/**
 * 首页接口
 */
class Index extends CompanyApi
{
    protected $noNeedLogin = ['departments'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     */
    public function index()
    {
        $this->success('请求成功');
    }

    /**
     * 公告
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getDynamics()
    {
//        var_dump('sdf');die;
        $user = $this->auth->getUser();
        $sql = "SELECT `id`,`content` FROM `fa_dynamic` where FIND_IN_SET({$user->department_id}, `department_ids`) ORDER BY `id` DESC";
        $list = Db::query($sql);
        $this->success('公告为', $list);
    }

    /**
     * 所有部门
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function departments()
    {
        $lists = Lists::field('id,name')->where('status', 'normal')->where('is_achievement', 1)->select();
        $this->success('部门列表', $lists);
    }

    /**
     * 物资分类
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function cates()
    {
        $list = \app\admin\model\product\Category::field('id,title')->where('status', 'normal')->order('sort asc,id desc')->select();
        $this->success('物资分类', $list);
    }
}
